<%
Function fc_i_login(str_user_id_input, str_pw_input)

fc_i_login = 0'default

'SYS
Session("ses_title")="Growmetry"
Session("ses_admin_log")="Admin"
Session("ses_first_log")="EX-"
Session("ses_i_first_log")=0'1=first login 0=kein first login
Session("ses_i_log")=0'0=first login (key)
Session("ses_Username_log")=0'eingabe login
Session("ses_Password_log")=0'eingabe login

Session("ses_str_user_id")="n/a"'die eingeloggte userid
Session("ses_str_User_info_all")="n/a"'die eingeloggte userid + head org + sub org + trainer
Session("ses_str_pw")="n/a"'das eigegebene pw
Session("ses_str_User_name")="n/a"'der eingeloggte username

Session("ses_path_sys")="http://localhost/www_zwick01/sys/main_menue.asp"
Session("ses_i")=0'zählt mit wie oft mit einer session (browserfenster) angemeldet wurde

Session("ses_iu")=0'user id
Session("ses_ig")=0'user group

Session("str_logfree")="A1"'ob userid und pw ok sind - A1 >> nein - A0 >> ok

Session("ses_str_master_id")="n/a"'die eindeutige vom system erstellt pw zb. lhQsnMNkBJIJ
Session("ses_str_log_id")="n/a"'die eindeutige vom system erstellt userid zb. E0-YNRKBFKUEE und ohne <E0->

'email
'i_type
'2 - Head Org	
'3 - Org		
'4 - Trainer		
'5 - Athlete
Session("ses_i_ebene")=0'von welcher ebene aus wird dsa email aufgerufen
Session("ses_i_email_template")=0'vorlage für das emailtemplate
Session("ses_user_email")=0'die mailadresse des eingelogten users
Session("ses_mail_from")="office@growmetry.com" 'Absender 
Session("ses_mail_to")="n/a"'emailadresse an wem das mail gesendet wird
Session("ses_mail_to_02")="n/a"'falls an eine zweite emailadresse gesendet wird
Session("ses_mail_subject")="n/a"
Session("ses_mail_body")="n/a"
Session("ses_mail_user_name")="n/a"'der name des user der das mail bekommen wird

'zeichenlaenge (min. laenge)
Session("ses_sub_org_len")=3
Session("ses_coach_len")=3
Session("ses_userid_len")=4
Session("ses_pw_len")=8
Session("ses_master_id")=12'zeichenlänge die eindeutige vom system erstellt pw zb. lhQsnMNkBJIJ
Session("ses_log_id")=10'zeichenlänge die eindeutige vom system erstellt userid zb. E0-YNRKBFKUEE und ohne <E0->

'schleifendurchlauf
Session("ses_i_pw_loop")=9999'wie oft bei der pw vergabe vom system eine schleife durchlaufen werden soll

'tmp session für die id des forms das geöffnet werden soll
'beim ersten login
Session("ses_frm_first_register")=0
'headorg
Session("ses_id_tmp_01")=0
Session("ses_frm_go_back_01")=0
'division
Session("ses_id_tmp_02")=0
Session("ses_frm_go_back_02")=0
'emailinfo
Session("ses_i_email_template")=0

'0 >> normalbetrieb - 1 > Applikation im entwicklungsstatus - nur für testbetrieb - es werden wichtige var ausgegeben
Session("ses_dev")=0

'das eindeutige pw für das erstmalige loggin
Session("ses_str_master_id")=0

'entscheidet ob mit diverse admin all frm gearbeitet werden darf oder nur seine eigenen stammdaten zu sehen sind
'Session("ses_i_stammdaten_look")=0

'id
Session("ses_i_usergroup")=0
Session("ses_i_admin")=1'zwick
Session("ses_i_head_org")=0'id des head org
Session("ses_i_org")=0'id des org
Session("ses_i_trainer")=0'id des trainers
Session("ses_i_athlete")=0'id des athleten

Session("ses_str_head_org")=0'string des head org
Session("ses_str_org")=0'string des org
Session("ses_str_trainer")=0'string des trainers
Session("ses_str_name_admin_head_org")=0'string des admin der head org
Session("ses_str_name_admin_division")=0'string des admin der division
Session("ses_str_name_admin_trainer")=0'string des admin der division

'id der letzten Auswahl... zb. wenn man ein Form verläßt und wieder zurück kommt wird das drop wiede so ausgewählt
'zb. trainer_admin_all.asp	
Session("ses_i_last_select_01")=0
Session("ses_i_last_select_02")=0

'isx = 0 >> keine neue stammdateneingabe übers login
'isx = 2 >> neue head org stammdateneingabe übers login
'isx = 3 >> neue org stammdateneingabe übers login
'isx = 4 >> neue trainer stammdateneingabe übers login
'isx = 5 >> neue athlete stammdateneingabe übers login	
Session("ses_i_isx")=0

'i_type 1=Admin / 2=Head Org / 3=Org / 4=Trainer / 5=Athlete
'wenn es ein login ist wo der benutzer selber auswählen kann ob er sub-org oder ein trainer ist
'dann ist >>Session("ses_i_type")=0
Session("ses_i_type")=0

'wenn es für den angelegt user eine dummy org (Non Commercial) darüber gibt >>> = 1	
Session("ses_i_dummy_head_org")=0
Session("ses_i_dummy_sub_org")=0

'killed alle sessions
'Session.Abandon
Dim queryStr
Dim rs
Dim rs_tmp

Dim str_user_id_short
Dim str_User_Last_Name
Dim str_User_First_Name
Dim str_head_organization
Dim str_sub_organization
Dim str_trainer

Dim i_fk_measured_system
Dim str_text_trennzeichen'zb: |
Dim i_user
Dim i_link_activate

Dim dt_pw_available_to
Dim lng_k_User_ID
Dim i_pos
Dim i
Dim str_logfree 'ob userid und pw ok sind - A1 > nein - A0 >> ok

Dim lng_fk_head_organization
Dim lng_fk_organization
Dim lng_fk_trainer
Dim lng_fk_athlete
Dim i_type

Dim i_dummy_head
Dim i_dummy_sub

Dim iu
Dim ig

Dim str_trenzeichen_info
str_trenzeichen_info = fc_value_string(Session("ses_i_language"), "var_glob_txt_1009")'das trennzeichen beim infotext rechts oben

Dim i_session

'20130511 überprüft ob es diess Login gibt
If Session("ses_iu") = 0 and Session("ses_ig") = 0 Then

	queryStr = "SELECT lng_k_User_ID, lng_fk_user_group FROM tbl_0501_user " & _
	"WHERE ((str_User_id='" & str_user_id_input & "') AND (str_pw='" & str_pw_input & "') AND (i_fk_status='1'));"
	
	Set rs = Server.CreateObject("ADODB.RecordSet")
	rs.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
	If Not rs.EOF Then	
		iu = rs.Fields("lng_k_User_ID").value
		ig = rs.Fields("lng_fk_user_group").value
	end if	
	rs.close
	set rs = Nothing

else
	'falls die log var schon leer ist
	iu = Session("ses_iu")
	ig = Session("ses_ig")
end if


'=========================================================================================================================================
'20130507 LOST PW 
'falls ein temp. PW eingegeben wurde
Dim lng_k_email_inquiry
Dim str_User_id_lpw
Dim i_login_lpw'0=nein - 1=ja
Dim sql_lost_lpw
Dim lng_k_User_ID_lpw
Dim str_pw_lpw
Dim iu_lpw
Dim ig_lpw
Dim str_pw_new_lpw

Dim dt_timestamp_2'		login using temporary password
Dim dt_timestamp_3'		NEW INSERTED    new password set by user
Dim str_pw_new	'	NEW INSERTED    new user password, after login using temporary password; or via user password (change password)

Dim i_len_new_pw

lng_k_email_inquiry = Null'Default
str_User_id_lpw = Null'default
i_login_lpw = 0 'Default
str_pw_new = Null
iu_lpw = Null
ig_lpw = Null

sql_lost_lpw = "SELECT " & _
"tbl_0903_pw_inquiry.lng_k_email_inquiry, " & _
"tbl_0903_pw_inquiry.str_User_id, " & _
"tbl_0903_pw_inquiry.str_temp_pw, " & _
"tbl_0903_pw_inquiry.dt_timestamp_2, " & _
"tbl_0903_pw_inquiry.str_pw_new, " & _
"tbl_0903_pw_inquiry.dt_timestamp_3, " & _
"tbl_0903_pw_inquiry.lng_fk_User_ID, " & _
"tbl_0501_user.lng_fk_user_group, " & _
"tbl_0501_user.str_User_First_Name, " & _
"tbl_0501_user.str_User_Last_Name, " & _
"tbl_0903_pw_inquiry.str_pw " & _
"FROM tbl_0903_pw_inquiry " & _
"Inner Join tbl_0501_user ON tbl_0903_pw_inquiry.lng_fk_User_ID = tbl_0501_user.lng_k_User_ID " & _
"WHERE  tbl_0903_pw_inquiry.str_User_id='" & str_user_id_input & "'  " & _
"AND tbl_0903_pw_inquiry.str_temp_pw='" & str_pw_input & "'"

'Response.Write("sql_lost_lpw #1: " & sql_lost_lpw & "<br>")
'response.End()

	Set rs = Server.CreateObject("ADODB.RecordSet")
	rs.Open sql_lost_lpw, objConn, adOpenStatic, adLockReadOnly
	
	If Not rs.EOF Then
		'call showMessage("Test - Lost PW")
		lng_k_email_inquiry = rs.Fields("lng_k_email_inquiry").Value
		str_User_id_lpw = rs.Fields("str_User_id").Value
		lng_k_User_ID_lpw = rs.Fields("lng_fk_User_ID").Value
		iu_lpw = rs.Fields("lng_fk_User_ID").Value
		ig_lpw = rs.Fields("lng_fk_user_group").Value
		str_pw_lpw = rs.Fields("str_pw").Value'das alte PW
		
		dt_timestamp_2 = rs.Fields("dt_timestamp_2").Value'login using temporary password
		dt_timestamp_3 = rs.Fields("dt_timestamp_3").Value'NEW INSERTED new password set by user
		str_pw_new = rs.Fields("str_pw_new").Value'NEW INSERTED new user password, after login using temporary password; or via user password (change password)
		
	end if'If rs.EOF then
	rs.Close 
	set rs = Nothing 
	

i_len_new_pw = len(str_pw_new)
If IsEmpty(i_len_new_pw) or IsNull(i_len_new_pw) Then
	i_len_new_pw = 0
end if

If IsEmpty(iu_lpw) or IsNull(iu_lpw) Then
	iu_lpw = 0
end if

If IsEmpty(ig_lpw) or IsNull(ig_lpw) Then
	ig_lpw = 0
end if
	
'#1 wenn der user mit dem temporary password sich einloggt und es schon ein neues PW gibt >> abbruch
	If Cint(iu_lpw) > 0 and Cint(ig_lpw) > 0 and Cint(i_len_new_pw) > 6 Then
		i_login_lpw = 1'login lost pw 	
		Session("ses_lpw_lng_k_email_inquiry")=Null 
		Session("ses_lpw_str_User_id")=Null
		
'Response.Write("step#1: " & "<br>")
	end if
	
'#2 wenn der user mit dem temporary password sich einloggt und es noch(!) kein neues PW gibt
If Cint(iu_lpw) > 0 and Cint(ig_lpw) > 0 and Cint(i_len_new_pw) = 0 Then'nur wenn es noch kein neues PW gibt
		'20130511 lost pw
		'für sergey >> daten aus der tabelle <tbl_0903_pw_inquiry>
		'das befüllen dieser Session var löst das PopUp im main für 
		'die Eingabe eines neuen PW aus!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		Session("ses_lpw_lng_k_email_inquiry")=lng_k_email_inquiry 
		Session("ses_lpw_str_User_id")=str_User_id_lpw
		i_login_lpw = 1'login lost pw
		
		'speichert beim ersten login einen Timestamp 
		Call save_first_log_tmp_pw (lng_k_email_inquiry, lng_k_User_ID_lpw)
		
'Response.Write("step#2: " & "<br>")
	else
'#3 wenn der user sich zum ersten mal mit dem neuen pw einloggt
		'überprüft ob es das timestamp in der tabelle [tbl_0903_pw_inquiry] gibt
		sql_lost_lpw = "SELECT dt_timestamp_3 FROM tbl_0903_pw_inquiry " & _
		"WHERE str_User_id ='" & str_user_id_input & "' AND str_pw_new ='" & str_pw_input & "'"
		
		Set rs = Server.CreateObject("ADODB.Recordset")
		rs.Open sql_lost_lpw, objConn, adOpenStatic, adLockReadOnly  
		If Not rs.EOF Then 
			dt_timestamp_3 = rs.Fields("dt_timestamp_3")
		end if
		rs.Close
		set rs = nothing
		
'Response.Write("sql_lost_lpw#3: " & sql_lost_lpw & "<br>")
'Response.Write("dt_timestamp_3: " & dt_timestamp_3 & "<br>")
		'response.End()
		
		If IsNull(dt_timestamp_3) or IsEmpty(dt_timestamp_3) Then
		  'speichert beim erstren login mit dem neuen pw das pw und den timestamp ab
		  Call save_dt_timestamp_3 (str_user_id_input, str_pw_input)
		end if

		Session("ses_lpw_lng_k_email_inquiry")=Null 
		Session("ses_lpw_str_User_id")=Null
		i_login_lpw = 0'normales login
		
'Response.Write("step#3: " & "<br>")
	end if

If i_login_lpw = 1 Then'login mit lost pw
	  iu = iu_lpw
	  ig = ig_lpw
end if

'Response.Write("sql_lost_lpw: " & sql_lost_lpw & "<br>")
'
'Response.Write("lng_k_email_inquiry: " & lng_k_email_inquiry & "<br>")
'Response.Write("str_User_id_lpw: " & str_User_id_lpw & "<br>")
'Response.Write("lng_k_User_ID_lpw: " & lng_k_User_ID_lpw & "<br>")
'Response.Write("iu_lpw: " & iu_lpw & "<br>")
'Response.Write("ig_lpw: " & ig_lpw & "<br>")
'Response.Write("i_login_lpw: " & i_login_lpw & "<br>")
'
'Response.Write("i_len_new_pw: " & i_len_new_pw & "<br>")
'Response.Write("str_pw_new: " & str_pw_new & "<br>")
'response.End()
'=========================================================================================================================================


If iu = 0 and ig = 0 Then
'überpürft es ob ein fingierter zugrifff ist------------------------------------------------------------------------------------------------------
'zum Beispiel
'Benutzername  ' OR '1'='1
'Passwort  ' OR '1'='1
'hochkomma
'check username
i_pos =  0
i_pos = Instr(str_user_id_input, "'")

If Cint(i_pos) > 0 then
	fc_i_login = 1'1=Anmeldung fehlgeschlagen
	'call showMessage(str_msg_01)'old Con_Msg_error >> "Bad accesses!"
    'Response.End()
end if

'check pw
i_pos =  0
i_pos = Instr(str_pw_input, "'")

If Cint(i_pos) >  0 then
	fc_i_login = 1'1=Anmeldung fehlgeschlagen
	'call showMessage(str_msg_01)'old Con_Msg_error >> "Bad accesses!"
    'Response.End()
end if

'istzeichen
'check username
i_pos =  0
i_pos = Instr(str_user_id_input, "=")

If Cint(i_pos) > 0 then
	fc_i_login = 1'1=Anmeldung fehlgeschlagen
	'call showMessage(str_msg_01)'old Con_Msg_error >> "Bad accesses!"
    'Response.End() 
end if
'check pw
i_pos =  0
i_pos = Instr(str_pw_input, "=")

If Cint(i_pos) > 0 then
	fc_i_login = 1'1=Anmeldung fehlgeschlagen
	'call showMessage(str_msg_01)'old Con_Msg_error >> "Bad accesses!"
   	'Response.End()
end if

Session("ses_Username_log")=str_user_id_input'eingabe login
Session("ses_Password_log")=str_pw_input'eingabe login
'##################################################################################################################
'NEU 2010 05 01 ohne überprüfung mit emaillink
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'first login-------------------------------------------------------------------------------------------------------------------------------
'ueberprueft die eingabe ------------------------------------------------------------------------------------------------------------------
'20090927
'änderung - es gibt nur einen key für alle drei ebenen
'der user entscheidet wohin er will
'Session("ses_first_log")="E0-"
'Session("ses_first_log_02")="EX-"

	'2009 11 06 manche user verwenden auch die systemzugangsdaten als ihr eigene user id und pw ------------
	'jetzt wird dies überprüft
	
	'man kann auch mit den systemzugangsdaten seine user id und pw eingeben
	'#1 zuerst muss überpürft werden falls der user ein EO- oder EX-... verwendet ob dieser nicht schon ein bestehender user
	'er kann ja zb nur mit dem E0-oder EX-.... und einen anderen PW arbeiten

	queryStr = "SELECT tbl_0501_user.lng_k_User_ID, tbl_0101_master_id.i_link_activate " & _
	"FROM tbl_0501_user, tbl_0101_master_id " & _
	"WHERE tbl_0501_user.lng_k_User_ID = tbl_0101_master_id.lng_fk_User_ID " & _
	"AND tbl_0501_user.str_user_id='" & str_user_id_input & "' " & _
	"AND tbl_0501_user.str_pw='" & str_pw_input & "' " & _
	"AND tbl_0501_user.i_fk_status='1'"
	
'Response.Write(queryStr & "<br>")
'Response.End()
	
	i_link_activate = 0'default
	i_user = 0 'default >> es wurde eine andere user id ohne "EO oder EX" eingetragen
	
	Set rs = Server.CreateObject("ADODB.RecordSet")
	rs.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
	If Not rs.EOF Then	
		i_user = rs.Fields("lng_k_User_ID").value
		i_link_activate = rs.Fields("i_link_activate").value
	end if	
	rs.close
	set rs = Nothing 

'Response.Write("i_user: " & i_user & "<br>")
'Response.Write("i_link_activate: " & i_link_activate & "<br>")
'Response.End()	

	'2011 01 19
	'wenn der user sein profil ausgefüllt hat aber trotzdem noch nicht aktiviert ist
	If i_user > 0 and i_link_activate = 0 Then'0 >> link noch nicht aktiviert 1>> link aktiviert
		'NEU 2010 05 01 aktiviert den USER (auch ohne emaillink)
		queryStr = "UPDATE tbl_0101_master_id SET i_link_activate = '" & 1 & "' WHERE lng_fk_User_ID ='" & i_user & "'"
		objConn.Execute queryStr
	end if
	
	'#2
	'jetzt wird nur noch überprüft ob dieser acount auch aktiviert ist	
	If Cint(i_user) = 0 Then	
	
	  queryStr = "SELECT i_link_activate FROM tbl_0101_master_id " & _
	  "WHERE str_master_id = '" & str_pw_input & "' AND str_log_id = '" & str_user_id_input & "'"
	  
'	Response.Write(queryStr & "<br>")
'	Response.End()
			
	  Set rs = Server.CreateObject("ADODB.RecordSet")
	  rs.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
	  If Not rs.EOF Then
		  i_link_activate = rs.Fields("i_link_activate").value
	  end if	
	  rs.close
	  set rs = Nothing
	
	end if'If Cint(i_user) = 0 Then	
	
	If Cint(i_link_activate) = 1 and Cint(i_user) = 0 and Len(str_user_id_input) > 0 and Len(str_pw_input) > 0 Then
		'call showMessage(str_msg_01)'old Con_Msg_error >> "Bad accesses!"
		fc_i_login = 1'1=Anmeldung fehlgeschlagen
	end if
	'-------------------------------------------------------------------------------------------------------
	'wenn der zugang noch nicht aktiviert wurde
	If str_user_id_short = Session("ses_first_log") and Cint(i_link_activate) = 0 or str_user_id_short = Session("ses_first_log_02") and Cint(i_link_activate) = 0 Then  
			
			i = 0 'default >> noch nicht abgelaufen
			
			queryStr = "SELECT COUNT(1) AS i FROM tbl_0101_master_id WHERE str_master_id = '" & str_pw_input & _
			"' AND str_log_id = '" & str_user_id_input & "' AND i_log = 0"
			Set rs = Server.CreateObject("ADODB.RecordSet")
			rs.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
				i = rs.Fields("i")
	'			Response.Write("i= " & i & "<br>")
	'			Response.Write(queryStr & "<br>")
	'			Response.End()
	'			rs.close
			set rs = Nothing 
	
		'#1b anmeldung mit der master id ist schon abgelaufen
		If Cint(i) = 0 Then
			fc_i_login = 2'2=Diese Login Information ist falsch oder nicht mehr gültig!
			'call showMessage(fc_value_string(Session("ses_i_language"), "var_main_m_32"))
			'"(10) Diese User Id ist schon abgelaufen. Sie darf nur bei der erstmaligen Anmeldung verwendet werden!"
		end if

	'#1a anmeldung mit einer first log id
	If Cint(i) = 1 Then

		'holt jetzt die id der referenz org id
		queryStr = "SELECT lng_fk_head_organization, lng_fk_organization, lng_fk_trainer, i_type, lng_fk_athlete " & _
		"FROM tbl_0101_master_id WHERE str_master_id = '" & str_pw_input & "' AND str_log_id = '" & str_user_id_input & "' AND i_log = 0"

'Response.Write(queryStr & "<br>")
'Response.End()	

		Set rs = Server.CreateObject("ADODB.RecordSet")
		rs.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
		If Not rs.EOF Then
			lng_fk_head_organization = rs.Fields("lng_fk_head_organization").Value
			lng_fk_organization = rs.Fields("lng_fk_organization").Value
			lng_fk_trainer = rs.Fields("lng_fk_trainer").Value
			lng_fk_athlete = rs.Fields("lng_fk_athlete").Value
			i_type = rs.Fields("i_type").Value
		end if
		rs.Close 
		set rs = Nothing 

'Response.Write("lng_fk_head_organization: " & lng_fk_head_organization & "<br>")
'Response.Write("lng_fk_organization: " & lng_fk_organization & "<br>")
'Response.Write("lng_fk_trainer: " & lng_fk_trainer & "<br>")
'Response.Write("lng_fk_athlete: " & lng_fk_athlete & "<br>")
'Response.Write("i_type: " & i_type & "<br>")
'Response.End()		
'---------------------------------------------------------------------------------------------------------------------------------------------------
		'überprüfung ob diese head-org eine dummy head org ist
		'wenn es für den angelegten user eine dummy head org (Non Commercial) darüber gibt >>> = 1	
		Session("ses_i_dummy_head_org")=0
		Session("ses_i_dummy_sub_org")=0

		'Login als head org admin oder als ein user der sich beim auswählen für eine sub org entscheidet
		If lng_fk_head_organization > 0 Then
			queryStr = "SELECT i_dummy FROM tbl_0190_head_organization WHERE lng_k_head_organization = '" & lng_fk_head_organization & "'"
			
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				i_dummy_head = rs_tmp.Fields("i_dummy").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing
			
			If i_dummy_head > 0 Then
				Session("ses_i_dummy_head_org")=1'= ein dummy
			end if
			
			'holt jetzt die <sub org id> falls die head org eine dummy ist
			If i_dummy_head > 0 Then
				queryStr = "SELECT lng_k_organization, i_dummy FROM tbl_0201_organization " & _
				"WHERE lng_fk_head_organization = '" & lng_fk_head_organization & "' AND i_dummy = '1'"
				Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
				rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
				If Not rs_tmp.EOF Then
					i_dummy_head = rs_tmp.Fields("i_dummy").Value
					lng_fk_organization = rs_tmp.Fields("lng_k_organization").Value'
				end if
				rs_tmp.Close 
				set rs_tmp = Nothing
			end if

		end if'If lng_fk_head_organization > 0 Then

		'Login als division admin
		If lng_fk_organization > 0 Then
			'#1 zuerst muss die head org id ermittelt werden
			queryStr = "SELECT lng_fk_head_organization, i_dummy FROM tbl_0201_organization WHERE lng_k_organization = '" & lng_fk_organization & "'"
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				lng_fk_head_organization = rs_tmp.Fields("lng_fk_head_organization").Value
				i_dummy_sub = rs_tmp.Fields("i_dummy").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing

			If i_dummy_sub > 0 Then
				Session("ses_i_dummy_sub_org")=1
			end if
			
			queryStr = "SELECT i_dummy FROM tbl_0190_head_organization WHERE lng_k_head_organization = '" & lng_fk_head_organization & "'"
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				i_dummy_head = rs_tmp.Fields("i_dummy").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing
			
			If i_dummy_head > 0 Then
				Session("ses_i_dummy_head_org")=1
			end if
			
		end if'If lng_fk_organization > 0 Then
		
		'Login als Trainer
		If lng_fk_trainer > 0 Then
			'#2 zuerst muss die sub org id ermittelt werden
			queryStr = "SELECT lng_fk_organization FROM tbl_0301_trainer WHERE lng_k_trainer = '" & lng_fk_trainer & "'"
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				lng_fk_organization = rs_tmp.Fields("lng_fk_organization").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing

			'#3 zuerst muss die head org id ermittelt werden
			queryStr = "SELECT lng_fk_head_organization, i_dummy FROM tbl_0201_organization WHERE lng_k_organization = '" & lng_fk_organization & "'"
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				lng_fk_head_organization = rs_tmp.Fields("lng_fk_head_organization").Value
				i_dummy_sub = rs_tmp.Fields("i_dummy").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing

			If i_dummy_sub > 0 Then
				Session("ses_i_dummy_sub_org")=1
			end if
			
			queryStr = "SELECT i_dummy FROM tbl_0190_head_organization WHERE lng_k_head_organization = '" & lng_fk_head_organization & "'"
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				i_dummy_head = rs_tmp.Fields("i_dummy").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing
			
			If i_dummy_head > 0 Then
				Session("ses_i_dummy_head_org")=1
			end if
		end if'If lng_fk_trainer > 0 Then

		'Login als athlete
		If lng_fk_athlete > 0 Then
			'#1 zuerst muss die trainer id id ermittelt werden
			queryStr = "SELECT lng_fk_trainer FROM tbl_0401_athlete WHERE lng_k_athlete = '" & lng_fk_athlete & "'"
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				lng_fk_trainer = rs_tmp.Fields("lng_fk_trainer").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing

			'#2 zuerst muss die sub org id ermittelt werden

			queryStr = "SELECT lng_fk_organization FROM tbl_0301_trainer WHERE lng_k_trainer = '" & lng_fk_trainer & "'"
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				lng_fk_organization = rs_tmp.Fields("lng_fk_organization").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing

			'#3 zuerst muss die head org id ermittelt werden
			queryStr = "SELECT lng_fk_head_organization, i_dummy FROM tbl_0201_organization WHERE lng_k_organization = '" & lng_fk_organization & "'"
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				lng_fk_head_organization = rs_tmp.Fields("lng_fk_head_organization").Value
				i_dummy_sub = rs_tmp.Fields("i_dummy").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing

			If i_dummy_sub > 0 Then
				Session("ses_i_dummy_sub_org")=1
			end if
			
			queryStr = "SELECT i_dummy FROM tbl_0190_head_organization WHERE lng_k_head_organization = '" & lng_fk_head_organization & "'"
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				i_dummy_head = rs_tmp.Fields("i_dummy").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing
			
			If i_dummy_head > 0 Then
				Session("ses_i_dummy_head_org")=1
			end if

		end if'If lng_fk_athlete > 0 Then
'----------------------------------------------------------------------------------------------------------------------------------------------------
		Session("ses_i_usergroup") = 0'noch ohne zuweisung
		Session("ses_i_isx") = 0'>> noch keine neue stammdateneingabe übers login
		
		Session("ses_i_head_org")= lng_fk_head_organization
		Session("ses_i_org") = lng_fk_organization
		Session("ses_i_log")=0'0=first login (key)
		Session("ses_str_user_id") = fc_value_string(Session("ses_i_language"), "var_glob_txt_1005")'"New Login"
		Session("ses_str_User_name") = fc_value_string(Session("ses_i_language"), "var_glob_txt_1005")'"New Login"
		Session("ses_str_User_info_all") = fc_value_string(Session("ses_i_language"), "var_glob_txt_1005")'"New Login"
		Session("ses_id_tmp_02") = 0
		Session("ses_i_trainer")= lng_fk_trainer
		Session("ses_i_athlete") = lng_fk_athlete
		
		Session("ses_str_trainer") = ""
		Session("ses_str_head_org") = ""
		Session("ses_str_org") = ""
		
		'2011 12 30 für die textausgabe wer ist angemeldet
		Session("ses_txt_logininfo_z01")=0 'zeile 1
		Session("ses_txt_logininfo_z02")=0 'zeile 2
		Session("ses_txt_logininfo_z03")=0 'zeile 3
		
		If Session("ses_i_dummy_head_org")=1 Then'dummy login
			Session("ses_str_User_name") = fc_value_string(Session("ses_i_language"), "var_glob_txt_1005")'"New Login"
		end if
		
		Session("ses_str_master_id") = str_pw_input'hqdOur3YoPMg
		Session("ses_str_log_id")= str_user_id_input'EX-FPCGSYREBB
		
		If Cint(i_type) = 0 Then
			Session("ses_i_type")=0
			Session("ses_frm_first_register") = "registration_02.asp"
			Session("ses_i_first_log")=1'1=first login 0=kein first login
			'vor änderung registration_02.asp dann >>> introduction.asp
			Response.Write ("<SCRIPT LANGUAGE='Javascript'>this.location.href='introduction.asp';</SCRIPT>")
		end if
		
		'2010 01 02
		'i_type 1=Admin / 2=Head Org / 3=Org / 4=Trainer / 5=Athlete
		
		'isx = 0 >> keine neue stammdateneingabe übers login
		'isx = 2 >> neue head org stammdateneingabe übers login
		'isx = 3 >> neue org stammdateneingabe übers login
		'isx = 4 >> neue trainer stammdateneingabe übers login
		'isx = 5 >> neue athlete stammdateneingabe übers login
		
		'usergroup
		''lng_fk_user_group
		'1	SuperVisor	SV 	Admin All
		'2	Head Org	HO 	Head Org Admin
		'3	Org			OR	Org Admin
		'4	Trainer		TR	Trainer Admin
		'5	Athlete		AT	Athlet Admin			

		If Cint(i_type) = 2 Then'Head Org
			Session("ses_i_type")= 2
			Session("ses_i_isx") = 2
			Session("ses_i_usergroup") = 2
			Session("ses_frm_go_back_02") = "index.asp"

			Session("ses_frm_first_register") = "head_org_user_admin_detail.asp?btnSub_02=N"
			Session("ses_i_first_log")=1'1=first login 0=kein first login
			
			'2011 12 30 für die textausgabe wer ist angemeldet
			Session("ses_txt_logininfo_z01")=fc_value_string(Session("ses_i_language"), "var_glob_txt_1021")'"zb: Angemeldet als:" 'zeile 1
			Session("ses_txt_logininfo_z02")=0'"zb: SK Sturm | Growmetry Administrator" 'zeile 2
			Session("ses_txt_logininfo_z03")=fc_value_string(Session("ses_i_language"), "var_glob_txt_1023")'"zb: Organisation | Funktion" 'zeile 3
			
			'vor änderung head_org_user_admin_detail.asp?btnSub_02=N dann >>> introduction.asp
			Response.Write ("<SCRIPT LANGUAGE='Javascript'>this.location.href='introduction.asp';</SCRIPT>")
		end if

		If Cint(i_type) = 3 Then'Sub Org
			Session("ses_i_type")= 3
			Session("ses_i_isx") = 3
			Session("ses_i_usergroup") = 3
			Session("ses_frm_go_back_02") = "index.asp"
			
			Session("ses_frm_first_register") = "org_user_admin_detail.asp?btnSub_02=N"
			Session("ses_i_first_log")=1'1=first login 0=kein first login
			'vor änderung org_user_admin_detail.asp?btnSub_02=N dann >>> introduction.asp
			Response.Write ("<SCRIPT LANGUAGE='Javascript'>this.location.href='introduction.asp';</SCRIPT>")
		end if

		If Cint(i_type) = 4 Then'Trainer
			Session("ses_i_type")= 4
			Session("ses_i_isx") = 4
			Session("ses_i_usergroup") = 4
			Session("ses_frm_go_back_02") = "index.asp"
			
			Session("ses_frm_first_register") = "trainer_user_admin_detail.asp?btnSub_02=N"
			Session("ses_i_first_log")=1'1=first login 0=kein first login
			'vor änderung trainer_user_admin_detail.asp?btnSub_02=N dann >>> introduction.asp
			Response.Write ("<SCRIPT LANGUAGE='Javascript'>this.location.href='introduction.asp';</SCRIPT>")
		end if

		If Cint(i_type) = 5 Then'Athlete
			Session("ses_i_type")= 5
			Session("ses_i_isx") = 5
			Session("ses_i_usergroup") = 5
			Session("ses_frm_go_back_02") = "index.asp"
			
			Session("ses_frm_first_register") = "athlete_user_admin_detail.asp?btnSub_02=N"
			Session("ses_i_first_log")=1'1=first login 0=kein first login
			'vor änderung athlete_user_admin_detail.asp?btnSub_02=N dann >>> introduction.asp
			Response.Write ("<SCRIPT LANGUAGE='Javascript'>this.location.href='introduction.asp';</SCRIPT>")
		end if
		
	end if'If Cint(i) = 1 Then '#1a anmeldung mit einer first log id
	
 end if'If str_user_id_short = Session("ses_first_log") and Cint(i_link_activate) = 0 or str_user_id_short = Session("ses_first_log_02") and Cint(i_link_activate) = 0 Then  
 
'end if'If iu = 0 and ig = 0 Then
'Response.Write("iu: " & iu & "<br>")
'Response.Write("ig: " & ig & "<br>")
'Response.Write("i_user: " & i_user & "<br>")
'Response.Write("ses_first_log: " & Session("ses_first_log") & "<br>")
'Response.Write("ses_first_log_02: " & Session("ses_first_log_02") & "<br>")
'Response.Write("i_link_activate: " & i_link_activate & "<br>")
'Response.Write("fc_i_login: " & fc_i_login & "<br>")
'Response.End()	

else

'Response.Write("iu: " & iu & "<br>")
'Response.Write("ig: " & ig & "<br>")
'Response.Write("i_user: " & i_user & "<br>")
'Response.Write("ses_first_log: " & Session("ses_first_log") & "<br>")
'Response.Write("ses_first_log_02: " & Session("ses_first_log_02") & "<br>")
'Response.Write("i_link_activate: " & i_link_activate & "<br>")
'Response.Write("fc_i_login: " & fc_i_login & "<br>")
'Response.End()	

'normales login----------------------------------------------------------------------------------------------------------------------------
'ueberprueft die eingabe ------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'normales login --------------------------------------------------

If Cint(i_login_lpw) = 0 Then'wenn es kein lost pw ist
queryStr = "SELECT str_User_id, str_pw, lng_fk_user_group, lng_fk_country, lng_k_User_ID, str_User_First_Name, str_User_Last_Name " & _
"FROM tbl_0501_user " & _
"WHERE ((str_User_id='" & str_user_id_input & "') AND (str_pw='" & str_pw_input & "') AND (i_fk_status='1'));"
end if

If Cint(i_login_lpw) = 1 Then'lost pw
	queryStr = sql_lost_lpw
end if

'Response.Write("queryStr: " & queryStr & "<br>")
'Response.End()
'-------------------------------------------------------------------------------------  
'20090501 - neue sicherheitsstufe - neues login
'Response.Write("ses_iu: " & Session("ses_iu") & "<br>")
'Response.Write("ses_ig: " & Session("ses_ig") & "<br>")

	If Session("ses_iu") = 0 AND Session("ses_ig") = 0 Then
      			Set rs = Server.CreateObject("ADODB.RecordSet") 
        		rs.Open queryStr, objConn, adOpenStatic, adLockReadOnly
				'check if login data could be retrieved from the database
				'if not login was not successfull
				If rs.EOF then
					'call showMessage(fc_value_string(Session("ses_i_language"), "var_glob_txt_1006"))'Con_Msg_02 >> "Wrong input!"
					fc_i_login = 1'1=Anmeldung fehlgeschlagen
					'******************************************************************************
					' alle fehlgeschlagenen login werden archiviert
					' addLogin      
					' add a login entry to the database
					' InputParameter:
					' password ... String
					' userId ... String
					' i_action ...integer...1 >> login...2 >> logout
					' i_session ... die anzahl der versuche bis zu einen gültigen login
					'******************************************************************************
					'Sub addLogin_error (password, userId, i_action, i_session)

					call addLogin_error (str_pw_input, str_user_id_input, 1, i_session)
					Response.Write ("<SCRIPT LANGUAGE='Javascript'>this.location.href='index.asp';</SCRIPT>") 
				else
				
					'ermittelt die log-id
					If Cint(i_login_lpw) = 0 Then'wenn es kein lost pw ist
						iu = rs.Fields("lng_k_User_ID").Value
						ig = rs.Fields("lng_fk_user_group").Value
						lng_k_User_ID = rs.Fields("lng_k_User_ID").Value
						i_fc_login = 1000'erfolgreiches login
					end if
					If Cint(i_login_lpw) = 1 Then'lost pw
						iu = iu_lpw
						ig = ig_lpw
						lng_k_User_ID = lng_k_User_ID_lpw
						i_fc_login = 1000'erfolgreiches login
					end if
					
					Session("ses_iu") = iu
					Session("ses_ig") = ig	
	
					Session("ses_str_User_id") = str_user_id_input
					Session("ses_i_log")=1'0=first login (key) - 1=normales login
	
					str_User_First_Name = ""
					str_User_Last_Name = ""
					Session("ses_str_User_name")= fc_get_username_voll(iu)

					'******************************************************************************
					' gibt den fremdschlüssel (zb. head org, sub org, trainer) des user zurück
					' InputParameter:
					' lng_k_User_ID ... id des user
					' i_info ... 1>> head org - 2>> suborg - 3>> trainer				
					'******************************************************************************
					'Function fc_lng_foreign_key(lng_k_User_ID, i_info)
					'ig >> usergroup
'usergroup
'lng_fk_user_group
'1	SuperVisor	SV 	Admin All
'2	Head Org	HO 	Head Org Admin
'3	Org			OR	Org Admin
'4	Trainer		TR	Trainer Admin
'5	Athlete		AT	Athlet Admin
					If ig = 1 Then
						Session("ses_i_head_org") = 1
						Session("ses_i_org") = 0
					end if
					If ig = 2 Then
						Session("ses_i_head_org") = fc_lng_foreign_key(iu, 1)
						Session("ses_i_org") = fc_lng_foreign_key(iu, 22)'???????????????
					end if
					If ig = 3 Then
						Session("ses_i_org") = fc_lng_foreign_key(iu, 2)
						Session("ses_i_head_org") = fc_lng_foreign_key(Session("ses_i_org"), 11)
					end if
					If ig = 4 Then
						Session("ses_i_trainer") = fc_lng_foreign_key(iu, 3)
						Session("ses_i_org") = fc_lng_foreign_key(Session("ses_i_trainer"), 23)
						Session("ses_i_head_org") = fc_lng_foreign_key(Session("ses_i_org"), 11)
					end if
					If ig = 5 Then
						Session("ses_i_athlete") = fc_lng_foreign_key(iu, 4)
						Session("ses_i_trainer") = fc_lng_foreign_key(Session("ses_i_athlete"), 33)
						Session("ses_i_org") = fc_lng_foreign_key(Session("ses_i_trainer"), 23)
						Session("ses_i_head_org") = fc_lng_foreign_key(Session("ses_i_org"), 11)
						lng_fk_trainer = Session("ses_i_trainer")
						lng_fk_athlete = Session("ses_i_athlete")
					end if
					
					lng_fk_head_organization = Session("ses_i_head_org")
					lng_fk_organization = Session("ses_i_org")

'wichtig >> weil wenn über das admin_overview oder admin_overview_id.asp ein anderes login aufgerufen wird wird dann sonst die eigene session auf 0 gesetzt	
Session("ses_str_userid_tmp")= str_user_id_input'zeichenfolge muss min 3 zeichen haben
Session("ses_str_pw_tmp")= str_pw_input
Session("ses_i_head_org_tmp") = Session("ses_i_head_org")					

				
					'lng_fk_user_group
					'1	SuperVisor	SV 	Admin All
					'2	Head Org	HO 	Head Org Admin
					'3	Org			OR	Org Admin
					'4	Trainer		TR	Trainer Admin
					'5	Athlete		AT	Athlet Admin
					Session("ses_i_usergroup") = ig
					Session("ses_i_last_select_01") = 0'default
					'Response.Write("ses_i_usergroup: " & Session("ses_i_usergroup") & "<br>")
				
					If ig = 1 Then'Admin
						Session("ses_str_User_info_all")= fc_value_string(Session("ses_i_language"), "var_glob_txt_1007")
						'"Administrator - " & Session("ses_str_User_name")'die eingeloggte userid + head org + sub org + trainer
						Session("ses_str_head_org")= fc_value_string(Session("ses_i_language"), "var_glob_txt_1007")'"Growmetry"
						Session("ses_str_org")="-"'string des org
 						Session("ses_str_trainer")="-"'string des trainers
					end if
					
					If ig = 2 Then'Head Org Admin
					str_head_organization = fc_str_head_org(lng_fk_head_organization)
						
						Session("ses_str_head_org")= str_head_organization
						Session("ses_str_org")="-"'string des org
 						Session("ses_str_trainer")="-"'string des trainers
					end if
					
					If ig = 3 Then'Division oder Typ B
						str_head_organization = fc_str_head_org(lng_fk_head_organization)
						str_sub_organization = fc_get_name_org(lng_fk_organization, 2)

						Session("ses_str_head_org")= str_head_organization
						Session("ses_str_org")= str_sub_organization
 						Session("ses_str_trainer")="-"'string des trainers
						
					end if

					If ig = 4 Then'Trainer oder Typ C
					
						str_head_organization = fc_str_head_org(lng_fk_head_organization)
						str_sub_organization = fc_get_name_org(lng_fk_organization, 2)
							'Response.Write("str_sub_organization: " & str_sub_organization & "<br>")
						str_trainer = fc_get_name_trainer(Session("ses_i_trainer"), 1)
						Session("ses_str_trainer")= str_trainer
					
						'2011 07 16 Typ A
						If lng_fk_head_organization > 1 Then
							str_head_organization = fc_str_head_org(lng_fk_head_organization)
						else
							str_head_organization = "-"
						end if
						
						'2011 07 06 Typ B
						If lng_fk_organization > 1 Then
							str_sub_organization = fc_get_name_org(lng_fk_organization, 2)
						else
							'gibt den namen des Trainers (Tabelle <tbl_0301_trainer> feld <str_trainer>) zurück
							'ist bei typ C der Orgname
							'******************************************************************************
							' gibt den namen des trainers zurück
							' InputParameter:
							' iu ... die id des datensatzes
							' i_info ... abfrageinfo
							'******************************************************************************
							'Function fc_get_name_trainer(id, i_info)
							str_sub_organization = fc_get_name_trainer(Session("ses_i_trainer"), 3)
						end if
						
						
						Session("ses_str_head_org")= str_head_organization
						Session("ses_str_org")= str_sub_organization
 						Session("ses_str_trainer")= str_trainer

					end if

					If ig = 5 Then'Athlete
					
						str_head_organization = fc_str_head_org(lng_fk_head_organization)
						str_sub_organization = fc_get_name_org(lng_fk_organization, 2)
						str_trainer = fc_get_name_trainer(lng_fk_trainer, 1)

						Session("ses_str_head_org")= str_head_organization
						Session("ses_str_org")= str_sub_organization
 						Session("ses_str_trainer")= str_trainer
					
					
					end if

'überprüft jetzt ob die login in ordnung sind
'ob userid und pw ok sind - 0 > OK  - 1 >> gesperrt
					'******************************************************************************
					' überprüft ob die zugangsdaten (userid und pw) eindeutig sind
					' InputParameter:
					' i_check ... 0 >> es wird nur überprüft ob die user id eindeutig ist / 1 >> user id und pw müssen zusammen eindeutig sein
					' str_user_id_input ... die eingegebene user id
					' str_pw_input ... das eingegebene passwort
					' lng_k_User_ID ... der aktuelle user
					' i_info ... ob es eine neuanlage ist (0) oder schon ein bestehender user ist (1)
					'******************************************************************************
					'ob userid und pw ok sind - A1 >> nein - A0 >> ok
					'Function fc_str_check_logindata(i_check, str_user_id_input, str_pw_input, lng_k_User_ID, i_info)
					str_logfree  = fc_str_check_logindata(1, str_user_id_input, str_pw_input, lng_k_User_ID, 1)
					If str_logfree = "A1" Then
						call showMessage(fc_value_string(Session("ses_i_language"), "var_glob_txt_1006"))
						'Your login details are not correct! Please change your USER ID or PASSWORD!
						Session("str_logfree") = "A1"
					else
						Session("str_logfree") = "A0"
					end if

					call addLogin (str_pw_input, str_user_id_input, 1, i_session, lng_k_User_ID)

'Response.Write("error#8" & "<br>")
'Response.End()						
					'lng_fk_user_group
					'1	SuperVisor	SV 	Admin All
					'2	Head Org	HO 	Head Org Admin
					'3	Org			OR	Org Admin
					'4	Trainer		TR	Trainer Admin
					'5	Athlete		AT	Athlet Admin
					
					'isx = 0 >> keine neue stammdateneingabe übers login
					'isx = 2 >> neue head org stammdateneingabe übers login
					'isx = 3 >> neue org stammdateneingabe übers login
					'isx = 4 >> neue coach stammdateneingabe übers login
					'isx = 5 >> neue child stammdateneingabe übers login
					Session("ses_i_isx") = 0
					
					'Überprüft ob dieses login auch aktiviert ist
					i_link_activate = 2
					queryStr = "SELECT i_link_activate FROM tbl_0101_master_id WHERE lng_fk_User_ID = '" & iu & "' "
					Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
					rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly   
				
					If Not rs_tmp.EOF Then
						i_link_activate = rs_tmp.Fields("i_link_activate").Value 
					end if
					
					rs_tmp.close 
					set rs_tmp = Nothing 
					
					'login falsch >> zurück zum loginfenster
'					call showMessage(i_link_activate)
'					Response.Write("queryStr: " & queryStr & "<br>")
'					Response.Write("i_link_activate: " & i_link_activate & "<br>")
					
					If i_link_activate = 0 Then'0 >> link noch nicht aktiviert 1>> link aktiviert
						'71 - wenn mit nicht zusammen passenden logindaten ein emaillink aktiviert werden soll	
						'call showMessage(Con_Msg_72)
						
						'NEU 2010 05 01 aktiviert den USER (auch ohne emaillink)
						queryStr = "UPDATE tbl_0101_master_id SET " & _
						"i_link_activate = '" & 1 & "'" & _
						" WHERE lng_fk_User_ID ='" & iu & "'"
						objConn.Execute queryStr
					end if

'---------------------------------------------------------------------------------------------------------------------------------------------------
'überprüfung ob diese head-org eine dummy head org ist
'wenn es für den angelegten user eine dummy head org (Non Commercial) darüber gibt >>> = 1	
		Session("ses_i_dummy_head_org")=0
		Session("ses_i_dummy_sub_org")=0

		'Login als head org admin oder als ein user der sich beim auswählen für eine sub org entscheidet
		If lng_fk_head_organization > 0 Then
			queryStr = "SELECT i_dummy FROM tbl_0190_head_organization WHERE lng_k_head_organization = '" & lng_fk_head_organization & "'"
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				i_dummy_head = rs_tmp.Fields("i_dummy").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing
			
			If i_dummy_head > 0 Then
				Session("ses_i_dummy_head_org")=1
			end if
			
			'call showMessage("Dummy Check")
		end if

		'Login als org admin
		If lng_fk_organization > 0 Then
			'#1 zuers_tmpt muss die head org id ermittelt werden
			queryStr = "SELECT lng_fk_head_organization, i_dummy FROM tbl_0201_organization WHERE lng_k_organization = '" & lng_fk_organization & "'"
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				lng_fk_head_organization = rs_tmp.Fields("lng_fk_head_organization").Value
				i_dummy_sub = rs_tmp.Fields("i_dummy").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing

			If i_dummy_sub > 0 Then
				Session("ses_i_dummy_sub_org")=1
			end if
			
			queryStr = "SELECT i_dummy FROM tbl_0190_head_organization WHERE lng_k_head_organization = '" & lng_fk_head_organization & "'"
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				i_dummy_head = rs_tmp.Fields("i_dummy").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing
			
			If i_dummy_head > 0 Then
				Session("ses_i_dummy_head_org")=1
			end if
			
			'call showMessage("Dummy Check")
		end if
		
		'Login als Trainer
		If lng_fk_trainer > 0 Then
			'#2 zuerst muss die sub org id ermittelt werden
			queryStr = "SELECT lng_fk_organization FROM tbl_0301_trainer WHERE lng_k_trainer = '" & lng_fk_trainer & "'"
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				lng_fk_organization = rs_tmp.Fields("lng_fk_organization").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing

			'#3 zuerst muss die head org id ermittelt werden
			queryStr = "SELECT lng_fk_head_organization, i_dummy FROM tbl_0201_organization WHERE lng_k_organization = '" & lng_fk_organization & "'"
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				lng_fk_head_organization = rs_tmp.Fields("lng_fk_head_organization").Value
				i_dummy_sub = rs_tmp.Fields("i_dummy").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing

			If i_dummy_sub > 0 Then
				Session("ses_i_dummy_sub_org")=1
			end if
			
			queryStr = "SELECT i_dummy FROM tbl_0190_head_organization WHERE lng_k_head_organization = '" & lng_fk_head_organization & "'"
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				i_dummy_head = rs_tmp.Fields("i_dummy").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing
			
			If i_dummy_head > 0 Then
				Session("ses_i_dummy_head_org")=1
			end if
		
		end if

		'Login als athlete
		If lng_fk_athlete > 0 Then
			'#1 zuerst muss die trainer id id ermittelt werden
			queryStr = "SELECT lng_fk_trainer FROM tbl_0401_athlete WHERE lng_k_athlete = '" & lng_fk_athlete & "'"
'			Response.Write(queryStr & "<br>")
'			Response.End()
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				lng_fk_trainer = rs_tmp.Fields("lng_fk_trainer").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing

			'#2 zuerst muss die sub org id ermittelt werden
			queryStr = "SELECT lng_fk_organization FROM tbl_0301_trainer WHERE lng_k_trainer = '" & lng_fk_trainer & "'"
'			Response.Write(queryStr & "<br>")
'			Response.End()
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				lng_fk_organization = rs_tmp.Fields("lng_fk_organization").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing

			'#3 zuerst muss die head org id ermittelt werden
			queryStr = "SELECT lng_fk_head_organization, i_dummy FROM tbl_0201_organization WHERE lng_k_organization = '" & lng_fk_organization & "'"
'			Response.Write(queryStr & "<br>")
'			response.End()
			
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				lng_fk_head_organization = rs_tmp.Fields("lng_fk_head_organization").Value
				i_dummy_sub = rs_tmp.Fields("i_dummy").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing

			If i_dummy_sub > 0 Then
				Session("ses_i_dummy_sub_org")=1
			end if
			
			queryStr = "SELECT i_dummy FROM tbl_0190_head_organization WHERE lng_k_head_organization = '" & lng_fk_head_organization & "'"
'			Response.Write(queryStr)
'			response.End()

			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				i_dummy_head = rs_tmp.Fields("i_dummy").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing
			
			If i_dummy_head > 0 Then
				Session("ses_i_dummy_head_org")=1
			end if
			
			'das voreingestellte messsytem wird ermittelt
			i_fk_measured_system = 1'metric default
			queryStr = "SELECT i_fk_measured_system FROM tbl_0801_athlete_measured " & _
			"WHERE lng_fk_User_ID = '" & lng_fk_athlete & "' AND i_fk_measured_type ='" & 1 & "'"
			'Response.Write(queryStr)
			Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
			rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
			If Not rs_tmp.EOF Then
				i_fk_measured_system = rs_tmp.Fields("i_fk_measured_system").Value
			end if
			rs_tmp.Close 
			set rs_tmp = Nothing

			Session("ses_i_measured_system") = i_fk_measured_system
			
		end if		
		'call showMessage("Dummy Check: " & Session("ses_i_dummy_head_org"))	
'--------------------------------------------------------------------------------------------------------------------------------------------------					

        	end if'If rs.EOF then
		rs.Close 
		set rs = Nothing 
		
'20101210 die sessions werden auf NULL gesetzt - wenn darüber keine ORGS gibt
'1 >>> bedeutet Dummy
If Session("ses_i_dummy_head_org") = 1 and Session("ses_i_dummy_sub_org") = 0 Then
	Session("ses_str_head_org") = "-"
	'Session("ses_str_org") = "-"
end if
If Session("ses_i_dummy_head_org") = 1 and Session("ses_i_dummy_sub_org") = 1 Then
	Session("ses_str_head_org") = "-"
	Session("ses_str_org") = "-"
end if

'2011 07 16 Ausnahme beim Typ C
If Session("ses_i_dummy_head_org") = 1 and Session("ses_i_dummy_sub_org") = 1 and ig = 4 Then'Trainer
	Session("ses_str_head_org") = "-"
	Session("ses_str_org") = fc_get_name_trainer(Session("ses_i_trainer"), 3)
end if

fc_i_login = 1000'erfolgreiches login	
	else

'noch offen????
Session("ses_iu") = 1'Admin
Session("ses_ig") = 1'SuperVisor
Session("ses_str_User_id") = "admin"
Session("ses_i_modul_01") = 3

	end if'If Session("ses_iu") = 0 AND Session("ses_ig") = 0 Then
end if'If iu > 0 and ig > 0 Then
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'dyn. menü

str_text_trennzeichen = fc_value_string(Session("ses_i_language"), "var_glob_txt_1009")'"New Login"
			
If Session("ses_i_usergroup") = 2 Then

'2011 12 30 für die textausgabe wer ist angemeldet
'2012 02 25 menü rechts oben hier eingelesen werde
Session("ses_txt_logininfo_z01")=fc_value_string(Session("ses_i_language"), "var_glob_txt_1021")'"zb: Angemeldet als:" 'zeile 1
Session("ses_txt_logininfo_z02")=Session("ses_str_head_org") & " " & str_text_trennzeichen & " " & fc_value_string(Session("ses_i_language"), "var_glob_txt_1024")'"zb: SK Sturm | Growmetry Administrator" 'zeile 2
Session("ses_txt_logininfo_z03")=fc_value_string(Session("ses_i_language"), "var_glob_txt_1023")'"zb: Organisation | Funktion" 'zeile 3

''admin_overview_dynamic.asp
'queryStr = "SELECT i_head_org FROM tbl_0504_user_reporting WHERE lng_fk_head_organization = '" & id_head_org & "' AND i_report ='" & 1 & "'"
''Response.Write(queryStr)
'Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
'rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
'If Not rs_tmp.EOF Then
'	i_report_01 = rs_tmp.Fields("i_head_org").Value
'end if
'rs_tmp.Close
'
''admin_overview_id.asp (mit Login)
'queryStr = "SELECT i_head_org FROM tbl_0504_user_reporting WHERE lng_fk_head_organization = '" & id_head_org & "' AND i_report ='" & 2 & "'"
''Response.Write(queryStr)
'Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
'rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
'If Not rs_tmp.EOF Then
'	i_report_02 = rs_tmp.Fields("i_head_org").Value
'end if
'rs_tmp.Close

end if 'If Session("ses_i_usergroup") = 2 Then

'Division
If Session("ses_i_usergroup") =  3 Then

'Response.Write("ses_i_dummy_head_org:" & Session("ses_i_dummy_head_org") & "<br>")
'Response.Write("ses_i_dummy_sub_org:" & Session("ses_i_dummy_sub_org") & "<br>")

'2011 12 30 für die textausgabe wer ist angemeldet
'2012 02 25 menü rechts oben hier eingelesen werde
Session("ses_txt_logininfo_z01")=fc_value_string(Session("ses_i_language"), "var_glob_txt_1021")'"zb: Angemeldet als:" 'zeile 1

If Session("ses_i_dummy_head_org") = 0 and Session("ses_i_dummy_sub_org") = 0 Then'Typ A >> Division
Session("ses_txt_logininfo_z02")=Session("ses_str_head_org") & " " & str_text_trennzeichen & " " & Session("ses_str_org") & " " & str_text_trennzeichen & " " & fc_value_string(Session("ses_i_language"), "var_glob_txt_1024")'"zb: SK Sturm | Growmetry Administrator" 'zeile 2
Session("ses_txt_logininfo_z03")=fc_value_string(Session("ses_i_language"), "var_glob_txt_1026")'"zb: Organisation | Funktion" 'zeile 3
end if

If Session("ses_i_dummy_head_org") = 1 and Session("ses_i_dummy_sub_org") = 0 Then'Typ B >> ORG
Session("ses_txt_logininfo_z02")= Session("ses_str_org") & " " & str_text_trennzeichen & " " & fc_value_string(Session("ses_i_language"), "var_glob_txt_1024")'"zb: SK Sturm | Growmetry Administrator" 'zeile 2
Session("ses_txt_logininfo_z03")=fc_value_string(Session("ses_i_language"), "var_glob_txt_1023")'"zb: Organisation | Funktion" 'zeile 3
end if

''admin_overview_dynamic.asp
'queryStr = "SELECT i_head_org FROM tbl_0504_user_reporting WHERE lng_fk_head_organization = '" & id_head_org & "' AND i_report ='" & 1 & "'"
''Response.Write(queryStr)
'Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
'rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
'If Not rs_tmp.EOF Then
'i_report_01 = rs_tmp.Fields("i_head_org").Value
'end if
'rs_tmp.Close
'
'i_report_02 = 0'kein öffen
'admin_overview_id.asp (mit Login)

end if 'If Session("ses_i_usergroup") =  3 Then

'Trainer
If Session("ses_i_usergroup") = 4 Then

'2011 12 30 für die textausgabe wer ist angemeldet
'2012 02 25 menü rechts oben hier eingelesen werde
Session("ses_txt_logininfo_z01")=fc_value_string(Session("ses_i_language"), "var_glob_txt_1021")'"zb: Angemeldet als:" 'zeile 1

'Nur bei typ C oder Typ B Trainer
If Session("ses_i_dummy_head_org") = 1 and Session("ses_i_dummy_sub_org") = 1 or Session("ses_i_dummy_head_org") = 1 and Session("ses_i_dummy_sub_org") = 0 Then
'"zb: SK Sturm | Growmetry Administrator" 'zeile 2
Session("ses_txt_logininfo_z02")= Session("ses_str_org") & " " & str_text_trennzeichen & " " & fc_value_string(Session("ses_i_language"), "var_glob_txt_1025")
'"zb: Organisation | Funktion" 'zeile 3
Session("ses_txt_logininfo_z03")=fc_value_string(Session("ses_i_language"), "var_glob_txt_1023")
else
'"zb: SK Sturm | Growmetry Administrator" 'zeile 2
Session("ses_txt_logininfo_z02")=Session("ses_str_head_org") & " " & str_text_trennzeichen & " " & Session("ses_str_org") & " " & str_text_trennzeichen & " " & fc_value_string(Session("ses_i_language"), "var_glob_txt_1025")
'"zb: Organisation | Funktion" 'zeile 3
Session("ses_txt_logininfo_z03")=fc_value_string(Session("ses_i_language"), "var_glob_txt_1026")
end if

''admin_overview_dynamic.asp
'queryStr = "SELECT i_head_org FROM tbl_0504_user_reporting WHERE lng_fk_head_organization = '" & id_head_org & "' AND i_report ='" & 1 & "'"
''Response.Write(queryStr)
'Set rs_tmp = Server.CreateObject("ADODB.RecordSet")
'rs_tmp.Open queryStr, objConn, adOpenStatic, adLockReadOnly  
'If Not rs_tmp.EOF Then
'i_report_01 = rs_tmp.Fields("i_head_org").Value
'end if
'rs_tmp.Close
'
'i_report_02 = 0'kein öffnen
'admin_overview_id.asp (mit Login)

end if 'If Session("ses_i_usergroup") = 4 Then

'Athlete
If Session("ses_i_usergroup") = 5 Then

'2011 12 30 für die textausgabe wer ist angemeldet
'2012 02 25 menü rechts oben hier eingelesen werde
Session("ses_txt_logininfo_z01")=fc_value_string(Session("ses_i_language"), "var_glob_txt_1020")'"zb: Angemeldet als:" 'zeile 1
Session("ses_txt_logininfo_z02")=Session("ses_str_head_org") & " " & str_text_trennzeichen & " " & Session("ses_str_org") & " " & str_text_trennzeichen & " " & Session("ses_str_trainer")'"zb: SK Sturm | Growmetry Administrator" 'zeile 2
Session("ses_txt_logininfo_z03")=fc_value_string(Session("ses_i_language"), "var_glob_txt_1022")'"zb: Organisation | Funktion" 'zeile 3

end if 		

End Function 
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'speichert beim ersten login einen Timestamp 
Sub save_first_log_tmp_pw (lng_k_email_inquiry, lng_k_User_ID)

Dim sql_lpw_01
Dim dt_timestamp

dt_timestamp = Now() 'Now()'CURRENT_TIMESTAMP()
'Function fc_str_date_server_format(dt_date, i_format)
dt_timestamp = fc_str_date_server_format(dt_timestamp, 4)

If Clng(lng_k_User_ID) > 0 and Clng(lng_k_email_inquiry) > 0  Then

	sql_lpw_01 = "UPDATE tbl_0903_pw_inquiry SET " & _
	"dt_timestamp_2= '" & dt_timestamp & "'" & _
	" WHERE lng_fk_User_ID = '"  & lng_k_User_ID & "' " & _
	"AND lng_k_email_inquiry ='" & lng_k_email_inquiry & "'"

'Response.Write(sql_lpw_01) 
'Response.End()
  
	objConn.Execute sql_lpw_01
	
end if

end sub 
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------
'speichert beim erstren login mit dem neuen pw das pw und den timestamp ab
Sub save_dt_timestamp_3 (str_user_id_input, str_pw_input)

Dim sql_lpw_01
Dim dt_timestamp

dt_timestamp = Now() 'Now()'CURRENT_TIMESTAMP()
'Function fc_str_date_server_format(dt_date, i_format)
dt_timestamp = fc_str_date_server_format(dt_timestamp, 4)

'If Clng(lng_k_User_ID_lpw) > 0 and Clng(lng_k_email_inquiry) > 0  Then

	sql_lpw_01 = "UPDATE tbl_0903_pw_inquiry SET " & _
	" dt_timestamp_3= '" & dt_timestamp & "'" & _
	" WHERE str_User_id = '"  & str_user_id_input & "' " & _
	"AND str_pw_new ='" & str_pw_input & "'"

'Response.Write(sql_lpw_01) 
'Response.End()

	objConn.Execute sql_lpw_01

	
'end if

end sub 
'------------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------------


%>



